fix: handle template literals in startsWith #182
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relates to: #181
Description
I needed to have more granular control over the comparison, so I replaced the
${S}${string}
part with
${infer THead}${infer TRest}
I needed to remove
Length<T>
in a lot of places -- it doesn't work with template literals.Details
Length
does not (and cannot) handle string interpolation well.Slice<T, startIndex, endIndex>
usesLength<T>
as the default value forendIndex
.Both
StartsWith
/EndsWith
useSlice
.I refactored
Slice
/StartsWith
/EndsWith
to not useLength
(or only use it whenT
is known to be a literal) and I now have them working with template literals.Also,
slice
/startsWith
/endsWith
are not methods with default number arguments (eg:0
orLength<T>
), they are overloads where the last arguments are optionally provided.Consider
In other words, updating the params for these types to be
P: number | undefined = undefined
instead of
P: number = Length<T>
makes this fix possible and more closely aligns our types with the TS definitions for those string methods.